package com.tyros.storage.config;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.env.EnvironmentPostProcessor;
import org.springframework.core.env.ConfigurableEnvironment;
import org.springframework.core.env.MutablePropertySources;
import org.springframework.core.env.PropertiesPropertySource;
import org.springframework.stereotype.Component;

import java.util.Properties;

/**
 * @author zhangshuaiyin
 * @date 2022/3/11 13:42
 */
@Component
public class TyrosPostProcessor implements EnvironmentPostProcessor {
    @Override
    public void postProcessEnvironment(ConfigurableEnvironment environment, SpringApplication application) {
        // 无效，读取该配置在此逻辑之前
        MutablePropertySources propertySources = environment.getPropertySources();
        Properties properties = new Properties();
        properties.setProperty("jasypt.encryptor.password", "tyros-resource");
        propertySources.addLast(new PropertiesPropertySource("applicationConfig: [classpath:/application.yml]", properties));
    }
}
